home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15762 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: erich.triumf.ca!bennett
  2. From: bennett@erich.triumf.ca (P.Bennett)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: strncpy() ?
  5. Date: 21 Apr 1996 11:08 PST
  6. Organization: TRIUMF: Tri-University Meson Facility
  7. Distribution: world
  8. Message-ID: <21APR199611080510@erich.triumf.ca>
  9. References: <4ldkvd$553@venus.compulink.gr>
  10. NNTP-Posting-Host: ftp.triumf.ca
  11. News-Software: VAX/VMS VNEWS 1.50    
  12.  
  13. In article <4ldkvd$553@venus.compulink.gr>, lonewolf@athena.compulink.gr (Costas Vlassis) writes...
  14. >    Well I have this question, let's say we have the following :
  15. >char alfa[40] = "1123";
  16. >char beta[20];
  17. >char gama[20];
  18. >With strncpy(beta,alfa,2) beta = "11" that's fine but HOW can I make 
  19. >gama = "23" that is the last 2 characters of alfa or even "3" the last 
  20. >character... Is there a function that takes start and end as strings ?
  21. >what I want is something like :
  22. >strncpy2 (beta,alfa,2,4);
  23.  
  24.     strncpy(gamma, alfa+2, 2);
  25. will (if I've counted correctly) copy "23" to gamma.
  26.  
  27. Beware that strncpy() usually does _not_ terminate what it copies with '\0', so
  28. you will have to do that manually to make these legal C strings.
  29.  
  30. Peter Bennett VE7CEI                | Vessels shall be deemed to be in sight
  31. Internet: bennett@triumf.ca         | of one another only when one can be
  32. Packet: ve7cei@ve7kit.#vanc.bc.ca   | observed visually from the other
  33. TRIUMF, Vancouver, B.C., Canada     |                          ColRegs 3(k)
  34. GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
  35. or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
  36. or: http:://vancouver-webpages.com/peter/index.html
  37.  
  38.  
  39.  
  40.  
  41.